<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

/*
 * @author: Manh Nguyen
 * @email: manhnv@binhhoang.com
 * @date: 14.04.2012
 */

class Home extends CI_Controller {
	
	private $_data = array();
	
	function __construct()
	{
		parent::__construct();
		$this->load->model(array('lich_model','location_model','mobile_detect_loto_model'));
		$this->_data['locations']	=	$this->location_model->get_all();
	}
	
	public function index()
	{
		$this->_data['tmpl']	=	'client/home/index';
		$this->load->view('client/layout/content', $this->_data);
	}
	
	public function detect()
	{
		$lid	=	1;
		if($_SERVER['REQUEST_METHOD'] == 'POST')
		{
			$lid	=	$this->input->post('lid');
		}
		
		$location	=	$this->location_model->get_by(array('id' => $lid));
		$cur_date	=	date('y-m-d');
		$_data	=	array();
		if($location)
		{
			$_data	=	$this->mobile_detect_loto_model->order_by('date','DESC')->get_by(array('lid' => $location->id));
			$this->_data['data']		=	$_data;
			$this->_data['location']	=	$location;
		}
		
		$this->_data['tmpl']	=	'client/home/detect';
		$this->load->view('client/layout/content', $this->_data);
	}
	
	public function statistic()
	{
		$lid	=	1;
		$days	=	10;
		$result	=	array();
		
		if($_SERVER['REQUEST_METHOD'] == 'POST')
		{
			$lid	=	$this->input->post('lid');
			$days	=	$this->input->post('days');
		}
		
		$this->load->model('mobile_statistics_model');
		$location	=	$this->location_model->get_by(array('id' => $lid));
		if($location)
		{
			$_data	=	$this->mobile_statistics_model->order_by('update_date','DESC')->get_by(array('lid' => $location->id, 'num_statistics' => $days));
			if($_data){
				$result =	json_decode($_data->result);
			}
			$this->_data['result']	=	$result;
		}
		$this->_data['days']	=	$days;
		$this->_data['lid']		=	$lid;
		$this->_data['tmpl']	=	'client/home/statistic';
		$this->load->view('client/layout/content', $this->_data);
	}
	
	function cal()
	{
		$this->_data['lich']	=	$this->lich_model->get_new();
		$this->_data['tmpl']	=	'client/home/cal';
		$this->load->view('client/layout/content', $this->_data);
	}
}

/* End of file home.php */
/* Location: ./application/controllers/home.php */